package com.mcxx.handler.step;

import com.mcxx.aspect.annotation.BizTypeHandler;
import com.mcxx.common.exception.BizException;
import com.mcxx.constant.BusinessConstant;
import com.mcxx.handler.BizProcessHandler;
import com.mcxx.modules.miniSalvation.check.service.read.CheckReadService;
import com.mcxx.modules.miniSalvation.order.service.read.OrderReadService;
import com.mcxx.result.BaseResult;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.FailureCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;



@BizTypeHandler(recheckType = BusinessConstant.BIZ_RECHECK, operateStep = BusinessConstant.OPS_RH)
public class RecheckInHouseHandler extends BizProcessHandler {
    private final static Logger logger = LoggerFactory.getLogger(RecheckInHouseHandler.class);

    @Autowired
    private OrderReadService orderReadService;
    @Autowired
    private CheckReadService checkReadService;

    @Override
    protected BaseResult preProccess(Map<String, Object> params) {
        logger.info("检查是否可以执行入户调查操作，{}", params);
        String orderId = (String)params.get("orderId");

        String bizState = orderReadService.getBizStateByBizStateRange(orderId, Constant.BizState.WAIT_IN_HOUSE);
        if(CommonUtil.invalidArgs(bizState)){

            throw new BizException(FailureCode.ERR_20056);
        }


        if(Constant.BizStateNew.APPROVE_REJECT.equals(bizState) == false){
            return BaseResult.success();
        }


        String checkReportFile = checkReadService.getCheckFileObjectKey(orderId);

        if(CommonUtil.invalidArgs(checkReportFile)){
            throw new BizException(FailureCode.ERR_20055);
        }
        return BaseResult.success();
    }

    @Override
    protected BaseResult doProcess(Map<String, Object> params) {
        return new BaseResult(1);
    }
}
